
new WOW().init();



jQuery(window).on("scroll", function (e) {
	scroll_now = jQuery(window).scrollTop();
	if (scroll_now > 0) {
		$('.header').addClass('hasBg')
	} else {
		$('.header').removeClass('hasBg')
	}
});

$(document).on('mousewheel', function(event) {
	var delta = event.originalEvent.deltaY || -event.originalEvent.detail;
	if (delta > 0) {
		$('.header').addClass('hide')
	}
	 else {
		$('.header').removeClass('hide')
	}
});


$('#goTop').click(function () {
	$("html,body").animate({
		scrollTop: 0
	}, 1000);
})

$('.pheader .navbox').click(function () {
	$(this).toggleClass('activeBox')
	$('.menuList').stop().slideToggle();
})

$('.menuList .item .tb').click(function () {
	$(this).children('img').toggleClass('rotate');
	$(this).siblings('.types_top').stop().slideToggle();
	$(this).parents('.item').siblings().children('.types_top').stop().slideUp();
	$(this).parents('.item').siblings().find('img').removeClass('rotate');
})



const countItems = document.querySelectorAll('.count-item');
function onIntersection(entries, observer) {
	entries.forEach(entry => {
		if (entry.isIntersecting) {
			const e = entry.target;
			animateCount(e);
			// observer.unobserve(e);
		}
	});
}
const observer = new IntersectionObserver(onIntersection);
countItems.forEach(item => observer.observe(item));
function animateCount(e) {
	var demo = { score: 0 },
		scoreDisplay = e,
		to = e.getAttribute('data-to'),
		speed = e.getAttribute('data-speed') * 1;
	var re = /[^0123456789.]/g;
	var result;
	var array = [];
	while((result = re.exec(to)) !==null){
		result.index = to.length-result.index-1
		array.unshift(result)
	}
	var automatic = 0;
	if (to !== null) {
		if (to.indexOf('.') !== -1) {
			automatic = (to.length -1)-to.indexOf('.')
		}
	}
	if (speed === 0) {
		speed = 1;
	}
	TweenLite.to(demo, speed, {
		score: to.replaceAll(re,''),
		onUpdate: showScore
	});
	function showScore() {
		scoreDisplay.innerHTML = formatNumberWithCommasAndDecimal(demo.score, automatic, array);
	}
}
function formatNumberWithCommasAndDecimal(number, decimalPlaces,separator) {
	var formattedNumber = number.toFixed(decimalPlaces);
	if(separator.length>0){
		for(let i=0;i<separator.length;i++){
			if(formattedNumber.length>separator[i].index){
				formattedNumber = formattedNumber.slice(0,formattedNumber.length-separator[i].index)+separator[i][0]+formattedNumber.slice(formattedNumber.length-separator[i].index)
			}
		}
	}
	return formattedNumber;
}